package cn.wolfcode.luowowo.mgrsite.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.query.DestinationQueryObject;
import cn.wolfcode.luowowo.article.query.RegionQueryObject;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.domain.AjaxResult;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Reference
    private IDestinationService destinationService;

    /**
     * 区域管理页面
     */
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQueryObject qo) {

        PageInfo pageInfo = destinationService.queryForPageInfo(qo);
//
        model.addAttribute("pageInfo", pageInfo);

        List<Destination>  toasts = new ArrayList<Destination>();

        toasts = destinationService.getToasts(qo.getParentId());

        model.addAttribute("toasts", toasts);

        return "destination/list";

    }

    /**
     * 改变热度
     * @return  操作结果
     */
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public AjaxResult changeHotValue(int hot, Long id) {


        AjaxResult ajaxResult = new AjaxResult();

        destinationService.changeHotValue(hot,id);

        return ajaxResult;

    }

    /**
     * 删除指定目的地数据
     * @return  操作结果
     */
    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(Long id) {


        AjaxResult ajaxResult = new AjaxResult();

        destinationService.delete(id);

        return ajaxResult;

    }

    /**
     * 编辑简介
     * @return  操作结果
     */
    @RequestMapping("/setInfo")
    @ResponseBody
    public AjaxResult setInfo(Long id,String info) {


        AjaxResult ajaxResult = new AjaxResult();

        destinationService.setInfo(id,info);

        return ajaxResult;

    }
}
